<template>
  <div class="">
    <dt-modal-edit
      ref="edit"
      :title="title"
      :label-width="100"
      okText="确定"
      :width="600"
      @ok="onOk"></dt-modal-edit>
  </div>
</template>

<script>
  import editOpt from '../biz/editOpt'
  import mgr from '../biz'
  import dt from '@dt/dt'

  export default {
    data() {
      return {
        title: '',
        info: {}
      }
    },
    methods: {
      show(data = {}) {
        this.info = Object.assign(
          {
            dataType: null,
            content: null,
            attachList: [],
            housesId: dt.buildInfo().housesId
          },
          data
        )
        this.title = data.housesDataId ? '上传' : '编辑'
        this.$refs.edit.show(editOpt.options(this), this.info)
      },
      onOk(data) {
        mgr.edit(data).then((res) => {
          this.$Message.success(`${this.info.housesDataId ? '上传成功' : '创建成功'}`)
          this.$refs.edit.hide()
          this.$emit('success', data.dataType)
        })
      }
    },
    mounted() {}
  }
</script>
<style lang="scss" scoped></style>
